package com.rrjjg.app.mybatis.config;

import com.alibaba.druid.pool.DruidDataSource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * ----------------------------------------------------------------------------- <br>
 * 功能 :  <br>
 * ----------------------------------------------------------------------------- <br>
 * 作者 : Vayne <br>
 * 时间 : 2023/4/8 <br>
 */
@Slf4j
@Component
public class PrintLineRunning implements CommandLineRunner, ApplicationContextAware {

    private ApplicationContext applicationContext;

    @Override
    public void run(String... args) throws Exception {
        DruidDataSource dataSource = applicationContext.getBean(DruidDataSource.class);
        log.info("druidDataSourece info \n\t" +
                        "url={}\n\t" +
                        "username={}\n\t" +
                        "driverClassName={}\n\t" +
                        "initialSize={}\n\t" +
                        "maxActive={}\n\t" +
                        "maxWait={}\n\t" +
                        "minIdle={}\n\t" +
                        "time-between-eviction-runs-millis={}\n\t" +
                        "min-evictable-idle-time-millis={}\n\t",
                dataSource.getUrl(),
                dataSource.getUsername(),
                dataSource.getDriverClassName(),
                dataSource.getInitialSize(),
                dataSource.getMaxActive(),
                dataSource.getMaxWait(),
                dataSource.getMinIdle(),
                dataSource.getTimeBetweenEvictionRunsMillis(),
                dataSource.getMinEvictableIdleTimeMillis());
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext=applicationContext;
    }
}
